/**
 * @filename:TuopanServiceImpl Dec 26, 2023
 * @project Wonder Vue Admin Api  1.1.0
 * Copyright(c) 2022 Wonder Co. Ltd. 
 * All right reserved. 
 */
package com.wonder.app.service.impl;

import com.wonder.app.domain.Tuopan;
import com.wonder.app.mapper.TuopanDao;
import com.wonder.app.service.TuopanService;
import com.wonder.app.request.TuopanRequest;
import com.wonder.common.utils.StringUtils;
import com.wonder.common.utils.MessageUtils;
import com.wonder.common.common.AjaxResult;

import java.util.Date;
import java.util.Map;
import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

/**   
 * @Description:TODO(托盘管理服务实现)
 *
 * @version: 1.1.0
 * @author: Wonder
 * 
 */
@Service
public class TuopanServiceImpl  extends ServiceImpl<TuopanDao, Tuopan> implements TuopanService  {

	@Autowired
	private TuopanDao tuopanDao;
	@Autowired
	private TuopanService tuopanService;

    /**
     * 验证托盘管理信息
     * 
     * @param tuopan
     * @param type
     * @return String
     */
    @Override
    public String validate(Tuopan tuopan,String type){
    
    
       return "";
    }
    
    
    /**
	 * Description:托盘管理分页返回
	 * @param request //检索条件
	 * @param page //分页参数
	 * @return IPage<Tuopan>   //分页记录
	 */
	@Override 
	public IPage<Tuopan> selectList(TuopanRequest request, Page<Tuopan> page){
	    LambdaQueryWrapper<Tuopan> lambdaQueryWrapper = new LambdaQueryWrapper<>();
	    
	    if (null != request.getFid()) {
	       lambdaQueryWrapper.eq(Tuopan::getFid, request.getFid());
	      }               
             
        
		lambdaQueryWrapper.orderByDesc(Tuopan::getFid);	
		Page<Tuopan> selectPage = this.baseMapper.selectPage(page, lambdaQueryWrapper);
		return selectPage;
    }


	@Override
	public boolean tuopanTijiao(Long fid) {
		Tuopan tuopan = tuopanDao.selectById(fid);

		//获取提交和审核状态
		String tj = tuopan.getTijiao().toString();
		boolean res ;
		if(tj == "true" ){
			res = false;
		}else{
			tuopan.setTijiao(true);
			res = tuopanService.updateById(tuopan);
		}
		return res;
	}
	@Override
	public boolean tuopanChexiao(Long fid) {
		Tuopan tuopan = tuopanDao.selectById(fid);

		//获取提交和审核状态
		boolean tj = tuopan.getTijiao();
		boolean sh = tuopan.getShenhe();
		boolean res ;
		if(tj == true && sh == false){
			tuopan.setTijiao(false);
			res = tuopanService.updateById(tuopan);
			//true;
		}else{
			res = false ;
		}

		return res;
	}

	@Override
	public boolean tuopanShenhe(Long fid) {
		Tuopan tuopan = tuopanDao.selectById(fid);
		//获取提交和审核状态
		boolean tj = tuopan.getTijiao();
		boolean sh = tuopan.getShenhe();
		boolean res;
		Date currentDate = new Date();
		tuopan.setAuditdate(currentDate);

		//当提交和审核状态是 true的时候，停止审核操作
		if(tj == true && sh == true  ){
			res = false;
		}
		else if(tj == true && sh == false ){
			tuopan.setShenhe(true);
			res = tuopanService.updateById(tuopan);
		}
		else{
			res = false;
		}
		return res;
	}
	@Override
	public boolean tuopanFanshenhe(Long fid) {
		Tuopan tuopan = tuopanDao.selectById(fid);
		//获取提交和审核状态
		boolean tj = tuopan.getTijiao();
		boolean sh = tuopan.getShenhe();
		boolean res ;

		if(tj == true && sh == true ){
			tuopan.setTijiao(false);
			tuopan.setShenhe(false);
			tuopanService.updateById(tuopan);
			res = true;
		}else {
			res = false;
		}
		return res;
	}
	
}